<div class="content-box"><!-- start_chungloai Content Box -->
    
    <div class="content-box-header">
        
        <h3>Quản lý chủng loại sản phẩm</h3>
        
        <ul class="content-box-tabs">
       
            <li><a href="#tab1" class="default-tab">Table</a></li> <!-- href must be unique and match the id of target div -->
            <li><a href="#tab2">Forms</a></li>
        </ul>
        
        <div class="clear"></div>
        
    </div> <!-- End .content-box-header -->
    
    <div class="content-box-content">
   
        <div class="tab-content default-tab" id="tab1"> <!-- This is the target div. id must match the href of this div's tab -->
        <?php
        $display_chungloai=20;
        if(isset($_GET['total_chungloai']) && (int)$_GET['total_chungloai']){
            $total_chungloai = $_GET['total_chungloai'];
        }else{
              $query='SELECT COUNT(id) FROM tbl_chungloai';
              $res = mysql_query($query);
              $row1=mysql_fetch_array($res);
              $record = $row1[0];
              if($record > $display_chungloai){
                  $total_chungloai = ceil($record/$display_chungloai);
              }else{
                  $total_chungloai=1;
              }
            }
        $start_chungloai = (isset($_GET['start_chungloai']) && (int)$_GET['start_chungloai']>=0)?$_GET['start_chungloai']:0;
        $stt=1;
        $sql='SELECT
	   					tbl_chungloai.id, 
						tbl_chungloai.chungloai,
						tbl_chungloai.anhcl,
						tbl_chungloai.danhmuc_id,
						tbl_chungloai.chungloai_id,
						tbl_danhmuc.danhmuc
		 				FROM tbl_chungloai
						INNER JOIN tbl_danhmuc ON tbl_chungloai.danhmuc_id=tbl_danhmuc.danhmuc_id
						ORDER BY id ASC LIMIT '.$start_chungloai.','.$display_chungloai.'';						
        $result=mysql_query($sql);
        $num=mysql_num_rows($result);	
        if($num>0)
        {
        ?>
            <table>
                
            
                    <tr  align="center">
                       <th>STT</th>
                       <th>Tên danh mục</th>
					   <th>Tên chủng loại</th>
                       <th>Ảnh chủng loại</th>
                       <th>Mã chủng loại</th>
                       <th>Action</th>
                    </tr>
                
                <?php
                while($row=mysql_fetch_array($result))
                {
                ?>					 
                
                    <tr valign="middle">
                        <td><?php echo $stt++;?></td>
                        <td valign="middle"><?php  echo $row['danhmuc'];?></td>
                        <td valign="middle"><a href="index.php?page=chungloai&act=edit&id=<?php echo $row['id'];?>"><?php  echo $row['chungloai'];?></a></td>
                        <td><img src="../uploads/<?php echo $row['anhcl']?>" width="110" height="86" class="sp-img"></td>
                        <td valign="middle"><?php  echo $row['chungloai_id'];?></td>
						<td valign="middle">
                            <!-- Icons -->
                             <a href="index.php?page=chungloai&act=edit&id=<?php echo $row['id'];?>" title="Edit"><img src="resources/images/icons/edit.png" alt="Edit" /></a>
                             <a href="index.php?page=chungloai&act=del&id=<?php echo $row['id'];?>" title="Delete" class="del"  onclick="return confirmSubmit()"><img src="resources/images/icons/del.png" alt="Delete" /></a>
                        </td>
                    </tr>
                
                <?php
                }
                ?>
                
                <tr>
                <?php
                    if($total_chungloai>1)
                    {
                        $next_chungloai=$start_chungloai + $display_chungloai;
                        $prev_chungloai=$start_chungloai - $display_chungloai;
                        $current_chungloai=($start_chungloai/$display_chungloai)+1;
                ?>
                    <td colspan="9">
                        
                        <div class="pagination" style="height:50px;">
                        <?php
                            //Hiển thị prev_chungloai
                            if($current_chungloai !=1)
                            {
                                echo '<a href="index.php?page=chungloai&start_chungloai='.$prev_chungloai.'" title="Previous Page">&laquo; Previous</a>';
                            }
                            //Hiển thị phân trang trong
                            for($i=1;$i<=$total_chungloai;$i++)
                            {
                                if($current_chungloai!=$i)
                                {
                                    echo '<a href="index.php?page=chungloai&start_chungloai='.($display_chungloai*($i-1)).'"  class="number" title="1">'.$i.'</a>';
                                }else
                                    {
                                        echo '<a class="number current">'.$i.'</a>';
                                    }
                            }
                            //Hiển thị next_chungloai
                            if($current_chungloai !=$total_chungloai)
                            {
                                echo '<a href="index.php?page=chungloai&start_chungloai='.$next_chungloai.'" title="Next Page">Next &raquo;</a>'; 
                            }
                        ?>
                        </div> <!-- End .pagination -->
                        <div class="clear"></div>
                    </td>
                    <?php
                    }
                    ?>
                </tr>
                
            </table>
    <?php
        }
    ?>
        </div> <!-- End #tab1 -->

             

    </div> <!-- End .content-box-content -->
    
</div> <!-- End .content-box -->
<script LANGUAGE="JavaScript">
    function confirmSubmit()
    {
        var agree=confirm("Bạn có chắc chắn xóa không?");
        if (agree)
            return true ;
        else
            return false ;
    }
</script>